﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using Microsoft.IdentityModel.Claims;

using bdtheque.business.interfaces;

namespace bdtheque.business.bo
{
    public class WIFHelper : IWIFHelper
    {
        private IClaimsPrincipal _claimsPrincipal;
        private IClaimsIdentity _identity;

        public WIFHelper(IClaimsPrincipal claimsPrincipal)
        {
            if (claimsPrincipal == null)
                throw new ArgumentNullException("ClaimsPrincipal");

            _claimsPrincipal = claimsPrincipal;
            _identity = (IClaimsIdentity)_claimsPrincipal.Identity;
        }

        public string GetClaimValue(string claimType)
        {
            var claim = _identity.Claims.SingleOrDefault(c => c.ClaimType.ToLower() == claimType);

            if(claim != null)
                return claim.Value;
            else
                return null;
        }
    }
}
